package com.example.adminserivce.Controller;

import com.example.adminserivce.Service.UserService;
import com.example.common.domain.Result;
import com.example.common.domain.dto.UserAndRole;
import com.example.common.domain.pojo.User;
import com.example.common.utils.RoleContext;
import com.example.common.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope//时时刷新配置信息
@Slf4j  //日志  log.info("登录日志测试：");
@RequestMapping("/admins")
@RequiredArgsConstructor
@Api(value = "管理员端接口", description = "基础用户信息")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("获取用户信息")
    @GetMapping("/getUserById/{id}")
    public Result<User> getUserById(@PathVariable String id) {
        return Result.success(userService.getUserByIdWithLogicalExpire(id));
    }


    @ApiOperation("获取当前登录id和权限，test，没有用")
    @GetMapping("/getLoginIdAndRole")
    public Result<UserAndRole> getById() {
        UserAndRole userAndRole = new UserAndRole();
        userAndRole.setId(UserContext.getUser());
        userAndRole.setRole(RoleContext.getRole());
        return Result.success(userAndRole);
    }




}
